<?php
session_start();
require_once ('config.php');
$errflag = false;
?>
<html>
<head>
<title>Search Feedback</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
<SCRIPT TYPE="text/javascript">
//This function is for making a pop up window when you press "Buy Ticket Online"

function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=450,height=350,scrollbars=yes');
return false;
}

</SCRIPT>
</head>
<body>
<?php
include_once ("common.php");
printHeader();
?>

<form align=right name=form method=post action="search-feedback.php" >
<input type=text name=moviefeedback size="12"><input type=submit value="search movie"></td>
</form>


<?php


$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$con)
	die('Could not connect: ' . mysql_error());

mysql_select_db(DB_DATABASE, $con);

echo "<table id=\"movie_table\"><tr>";

if ($_GET[movie] != NULL) {
	$sqlresult = mysql_query("select m.name, m.rating, m.picture_path, f.userrating, f.feedback, f.userID from movielist m, feedback f where m.name like '%$_GET[movie]%' and m.ID=f.movieID ");
} else
	if ($_POST[moviefeedback] != NULL) {
		#$sqlresult = mysql_query("SELECT * FROM feedback WHERE moviename='$_POST[moviefeedback]'");
		$sqlresult = mysql_query("select m.name, m.rating, m.picture_path, f.userrating, f.feedback, f.userID from movielist m, feedback f where m.name like '%$_POST[moviefeedback]%' and m.ID=f.movieID ");
	} else {
		$sqlresult = mysql_query("select m.name, m.rating, m.picture_path, f.userrating, f.feedback, f.userID from movielist m, feedback f where m.ID=f.movieID");
	}

echo "<table border='1'>
	<tr>
	<th><h3>Movie</h3></th>
    <th><h3>Poster</h3></th>
	<th><h3>Rating</h3></th>
	<th><h3>User Rating</h3></th>
	<th><h3>User</h3></th>
    <th><h3>Movie Feedback</h3></th>
	</tr>";
while ($row = mysql_fetch_array($sqlresult)) {
	//echo $row['moviename'] . " " . $row['userrating']."   ". $row['feedback'];
    $path = "$row[picture_path]";
	echo "<td>" . $row['name'] . "</td>";
	echo "<td><img src='" . $path . "' width=\"140px\" height=\"180px\" alt='" . $path . "'></td>";
	echo "<td>" . $row['rating'] . "</td>";
	echo "<td>" . $row['userrating'] . "</td>";
	echo "<td>" . $row['userID'] . "</td>";
	echo "<td>" . $row['feedback'] . "</td>";
	echo "</tr>";

} //end of while

echo "</table>";
?>
</body>
</html>